// moudle
import nodemailer from "nodemailer";
import yaml from "js-yaml";
import http from "node:http"
import fs from "node:fs";
import url from "node:url"
// 初始化邮件服务
const transport = nodemailer.createTransport({
    service:"qq", // 服务商
    host:"smtp.qq.com",
    port:465,
    secure:true,
    auth:{
        user:"201647997@qq.com",//邮箱账号
        pass:"zesbadanrdxibhgi" //密码或授权码
    }
})
http.createServer(async(req,res)=>{
    const {pathname} = url.parse(req.url);
    const {method} = req;
    if(method === "POST"&& pathname == "/send/mail"){
        // 发送文件
        let data = "";
        req.on("data",(chunk)=>{
            data += chunk;
        })
        req.on("end",()=>{
            const {to,subject,text} = JSON.parse(data)
            transport.sendMail({
                to,   // 收件人
                from:"201647997@qq.com",  // 发件人
                subject,
                text
            })
            res.end("ok")
        })
    }
}).listen(3000,()=>{
    console.log("linstening on port 3000");
});